<?php 
if (!isset($_SESSION)) {
  session_start();
  if(!isset($_SESSION['MM_Username']))
	header("location:../../index.php");
}
 
	require_once('../../Connections/microassur.php'); 
	require_once('../../utils/fonctions.php');	
	$message = '';

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

$maxRows_rs1 = 10;
$pageNum_rs1 = 0;
if (isset($_GET['pageNum_rs1'])) {
  $pageNum_rs1 = $_GET['pageNum_rs1'];
}
$startRow_rs1 = $pageNum_rs1 * $maxRows_rs1;

mysql_select_db($database_microassur, $microassur);
$query_rs1 = '';
if(isset($_GET['Identifiant_personne']) && !empty($_GET['Identifiant_personne'])){ // Vérifier si Identifiant_personne est passé en paramètre
	$ident = $_GET['Identifiant_personne'];
}else{
	$ident=-1;
}
	$query_rs1 = 'SELECT * FROM adresse WHERE Etat_adresse="A" AND Identifiant_personne= '. $ident;
 // End $_GET['Identifiant_personne']
//$query_limit_rs1 = sprintf("%s LIMIT %d, %d", $query_rs1, $startRow_rs1, $maxRows_rs1);
$query_limit_rs1 = $query_rs1;
$rs1 = mysql_query($query_limit_rs1, $microassur) or die(mysql_error());
// $row_rs1 = mysql_fetch_assoc($rs1);

if (isset($_GET['totalRows_rs1'])) {
  $totalRows_rs1 = $_GET['totalRows_rs1'];
} else {
  $all_rs1 = mysql_query($query_rs1);
  $totalRows_rs1 = mysql_num_rows($all_rs1);
}
$totalPages_rs1 = ceil($totalRows_rs1/$maxRows_rs1)-1;

mysql_select_db($database_microassur, $microassur);
$query_rs_personne = "SELECT * FROM personne";
$rs_personne = mysql_query($query_rs_personne, $microassur) or die(mysql_error());
$row_rs_personne = mysql_fetch_assoc($rs_personne);
$totalRows_rs_personne = mysql_num_rows($rs_personne);

$queryString_rs1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rs1") == false && 
        stristr($param, "totalRows_rs1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rs1 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rs1 = sprintf("&totalRows_rs1=%d%s", $totalRows_rs1, $queryString_rs1);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=8" />
			<title>Adresse</title>
			<link rel="stylesheet" type="text/css" href="../../css/main.css" />
            <link rel="stylesheet" type="text/css" href="list.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]-->
 
			<script language="Javascript">
            <!--
                function modifier(choix){
                    var modifAct = document.getElementById("modifAct");
					var suppAct = document.getElementById("suppAct");
        modifAct.href = 'modadresse.php?Identifiant_personne=<?php echo $_GET['Identifiant_personne']; ?>&Identifiant_adresse=' + choix ;
        suppAct.href = 'modadresse.php?Identifiant_personne=<?php echo $_GET['Identifiant_personne']; ?>&Identifiant_adresse=' + choix + '&supp=1' ;
                }
            //-->
            </script>
	</head>
<body>
<div id="sf_menu1">
	<h3>Production <?php //echo nomPersonne($database_microassur, $microassur, $_GET['Identifiant_personne']) ?></h3>

<?php
	if(isset($_GET['msg']) && $_GET['msg']=='1')
		$message = colorer("Une personne doit avoir au moins une adresse.","false");
		
	if(isset($_GET['msg']) && $_GET['msg']=='supp')
		$message = colorer("Adresse supprimée.","false");
		
	if(isset($_GET['msg']) && $_GET['msg']=='no')
		$message = colorer("Vous ne pouvez supprimer la seule adresse.","false");
	if(isset($message) && !empty($message)){
		echo $message;
	}
	$nommodule="Souscription contrat";
	$nommodule2="Liste des adresses";
	$nom_module_saisie="Ecran saisie";
?>
</div>
<div class="cleared"></div>

<div class="corps1">
<!--/***************************************/-->
	<div class="imgleft"></div>
	<div class="imgmiddle">
		<div class="btn">
        	<span class="btnleft"></span>
            <span class="btnmiddle">
            	<h5><?php echo $nommodule; ?></h5>
            </span><span class="btnright"></span>
        </div>
		<div class="btn1">
        	<span class="btnleft"></span>
            <span class="btnmiddle">
            	<h5><?php echo $nommodule2; ?></h5>
            </span><span class="btnright"></span>
        </div>
		<div class="cleared"></div>
<table class="tab_liste ns0">
  <tr id="niv1">
  	<td class="td1">&nbsp;</td>
    <td class="td2">TYPE</td>
    <td class="td3">ADRESSE</td>
  </tr>
</table>
    	<div class="content_table bright">
<table class="tab_list">
<?php
$i=1;
		
		while ($row_rs1 = mysql_fetch_assoc($rs1)){
			//medoune: REQUETE SUR LA TABLE DCTIONNAIE
			$reqdico = "Select DISTINCT(Identifiant_table) from dictionnaire where Code_table='M0004'";
			$rs_idtab_dico = mysql_query($reqdico, $microassur) or die(mysql_error());
			$row_idtab = mysql_fetch_assoc($rs_idtab_dico);
			
			
			//medoune: REQUETE SUR LA TABLE ELEMENTDICO
			$reqelmtdico = "Select DISTINCT(Nom_element) from elementdico where Identifiant_table='".$row_idtab['Identifiant_table']."' and Code_element='".$row_rs1['Type_adresse']."'";
			$rs_elmtdico = mysql_query($reqelmtdico, $microassur) or die(mysql_error());
			$row_elmtdico = mysql_fetch_assoc($rs_elmtdico);
			?>
			<tr <?php if($i%2==0) echo 'class="colorligne"'; ?>>
      <td class="td1">
      	<input onClick="modifier(this.value);" type="radio" name="choix" id="choix" value="<?php echo $row_rs1['Identifiant_adresse']; ?>" />
      </td>
      <td class="td2"><?php echo htmlentities($row_elmtdico['Nom_element'],ENT_COMPAT, 'utf-8'); ?></td>
      <td class="td3">
			<?php echo $row_rs1['Ligne1_adresse']." ".$row_rs1['Ligne2_adresse']." ".$row_rs1['Ligne3_adresse']; ?>
      </td>
    </tr>
			<?php
			$i++;
		}
 ?>
</table>
		</div>
						<div id="buttonright"><span class="btleft"></span><span class="btmiddle"><a href="insertadresse.php?Identifiant_personne=<?php echo $_GET['Identifiant_personne']?>">Créer</a></span><span class="btright"></span></div>
						<div id="buttonright"><span class="btleft"></span><span class="btmiddle"><a id="modifAct" href="#">Modifier</a></span><span class="btright"></span></div>
						<div id="buttonright"><span class="btleft"></span><span class="btmiddle"><a id="suppAct" href="#">Supprimer</a></span><span class="btright"></span></div>
	
	</div>
	<div class="imgright"></div>
	<div class="cleared"></div>
	<!--/***************************************/-->

<?php 
$nombreAdrActive = intval(nombreAdrActive($database_microassur, $microassur, $ident));

//if($nombreAdrActive>=1){ ?>
<div class="bt1">
	<a href="../contrat/saisiepersonne.php?Identifiant_personne=<?php echo $ident; ?>&medtest=0">
    	<span class="btleft"></span>
        <span class="btmiddle">Retour</span>
        <span class="btright"></span>
    </a>
</div>
<?php  /*}else{ ?>
<div class="bt1">
	<a href="../adresse/index.php?Identifiant_personne=<?php echo $ident; ?>">
    	<span class="btleft"></span>
        <span class="btmiddle">Retour</span>
        <span class="btright"></span>
    </a>
</div>
<?php $msg = '1'; } */ ?>

</body>
</html>
<?php

mysql_free_result($rs1);

//mysql_free_result($rs_lab_personne);

mysql_free_result($rs_personne);
?>
